package com.dm.library.widgets.swiperecyclerview.footerView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.dm.library.R;


/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述: <描述>
 * 修 改 人: sushuo
 * 修改时间: 2017-2-15
 */
public class SimpleFooterView extends BaseFooterView {

    private TextView mText;

    private LinearLayout footerLoadingLayout;
    private ProgressBar progressBar;

    public SimpleFooterView(Context context) {
        this(context, null);
    }

    public SimpleFooterView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleFooterView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        setLayoutParams(new LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_footer_view, this);
        footerLoadingLayout = (LinearLayout) view.findViewById(R.id.footer_loading_layout);
        progressBar = (ProgressBar) view.findViewById(R.id.footer_view_progressbar);
        mText = (TextView) view.findViewById(R.id.footer_view_tv);
    }

    @Override
    public void onLoadingMore() {
        footerLoadingLayout.setVisibility(VISIBLE);
        mText.setVisibility(GONE);
    }

    public void showText(){
        footerLoadingLayout.setVisibility(GONE);
        mText.setVisibility(VISIBLE);
    }

    @Override
    public void onNoMore(CharSequence message) {
        showText();
        if (message == null || message.length() == 0) {
            mText.setText("暂无更多数据");
        } else {
            mText.setText(message);
        }
    }

    @Override
    public void onLoadError(CharSequence message) {
        showText();
        if (message == null || message.length() == 0) {
            mText.setText("加载数据出错，点击重新加载");
        } else {
            mText.setText(message);
        }
    }

    @Override
    public void onNetChange(boolean isAvailable) {
        if (!isAvailable) {
            showText();
            mText.setText("网络异常，请稍后再试");
        }
    }
}
